﻿/******************************************************   
创建者: 曹亚亮
创建时间: 2017-06-24
修改:
修改时间: 
功能: 导出抢货结果
 ******************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.nm.library.Excels;
using System.Text.RegularExpressions;

namespace DistributeAPI.Export
{
    [Export(typeof(ExcelImport))]
    public class PickingOperationsExcel : ExcelImport
    {
        public override ExcelImportType Type => ExcelImportType.PICKINGOPERATIONS;
        public override Dictionary<string, ImportVerify> DictFields => _dictFields;

        private Dictionary<string, ImportVerify> _dictFields = new List<ImportVerify> {
            new ImportVerify { ColumnName="店铺编号",FieldName="ShopCode",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,30,true,true)},
            new ImportVerify{ ColumnName="店铺名称",FieldName="ShopName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,60,true,true)},
            new ImportVerify{ ColumnName="货号",FieldName="MaterialID",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,45,true,true)},
            new ImportVerify{ ColumnName="尺码名称",FieldName="SizeName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,120,true,true)},
            new ImportVerify{ ColumnName="抢货数量",FieldName="ActualQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,2,true,true)}
           }.ToDictionary(e => e.ColumnName, e => e); 

        public override object SaveImportData(DataTable dt, Dictionary<string, object> extraInfo, int userId)
        {
            throw new NotImplementedException();
        }

        public override DataTable GetExportData(string Keys)
        {
            var handler = new PickingOperationsHandler();
            var dt = handler.ExportDC_GetShopReqDetail(Keys);
            var regNum = new Regex("^[N]");
            for (var i = 0; i < dt.Columns.Count; i++)
            {
                if (regNum.IsMatch(dt.Columns[i].ColumnName))
                {
                    dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.Substring(1, dt.Columns[i].ColumnName.Length - 1);
                }
            }
            return dt;
        }
    }
}
